export const commonItem1 = {
    // 选择街道
    changeStreet(currentStreetId) {
        console.log(this.query.streetId, currentStreetId);
        this.showInput = false;
        console.log(this.showInput);
        if ("streetName" in this.query) {
            this.query.streetName = this.streetList.find(item => {
                return item.id === currentStreetId;
            }).name;
            this.query.communityName = "";
            this.query.villageName = "";
        }

        this.query.communityId = "";
        this.query.villageId = "";
        this.communityList = [];
        this.villageList = [];



    },
    visibleChangeStreet(bool) {
        if (bool) {
            this.getStreetList();
        }
        console.log(bool);
    },
    // 选择社区
    changeCommunity(currentCommunityId) {
        console.log(this.query.communityId, currentCommunityId);
        if ("communityName" in this.query) {
            this.query.communityName = this.communityList.find(item => {
                return item.id === currentCommunityId;
            }).name;
            this.query.villageName = "";
        }
        this.query.villageId = "";
        this.villageList = [];
    },
    visibleChangeCommunity(bool) {
        if (bool) {
            this.getCommunityList();
        }
        console.log(bool);
    },
    // 选择小区
    changeVillage(currentVillageID) {
        if ("villageName" in this.query) {
            this.query.villageName = this.villageList.find(item => {
                return item.id === currentVillageID;
            }).name;
        }
        this.query.villageId = currentVillageID
        console.log(this.query.villageId, currentVillageID);
    },
    visibleChangeVillage(bool) {
        if (bool) {
            this.getVillageList();
        }
        console.log(bool);
    },
    getStreetList() {
        this.$axios
            .get("/village/subdistrict/page", {
                params: {
                    parentId: 0
                }
            })
            .then(({ data: res }) => {
                console.log("街道数据", res);
                if (res.code != 0) {
                    return;
                }
                this.streetList = res.data.list;
            })
            .catch(() => { });
    },
    getCommunityList() {
        if (!this.query.streetId) {
            return this.$message.warning({
                message: "请先选择街道",
                duration: 1500
            });
        }
        // communityList
        this.$axios
            .get("/village/subdistrict/page", {
                params: {
                    parentId: this.query.streetId
                }
            })
            .then(({ data: res }) => {
                console.log("社区数据", res);
                if (res.code != 0) {
                    return;
                }
                this.communityList = res.data.list;
            })
            .catch(() => { });
    },
    getVillageList() {
        if (!this.query.communityId) {
            return this.$message.warning({
                message: "请先选择社区",
                duration: 1500
            });
        }

        this.$axios
            .get("/village/subdistrict/page", {
                params: {
                    parentId: this.query.communityId
                }
            })
            .then(({ data: res }) => {
                console.log("小区数据", res);
                if (res.code != 0) {
                    return;
                }
                this.villageList = res.data.list;
            })
            .catch(() => { });
    },
}